package com.abc.easyclaim;

import com.abc.tool.Constants;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class CommonEditActivity extends Activity implements OnClickListener{
	private TextView titleTextView;
	private TextView itemTextView;
	private EditText valueEditText;
	private Button saveButton;
	private String title;
	private String item;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_common_edit);
		//接收Intent参数
		Intent intent=getIntent(); 
        title=intent.getStringExtra("title");
        item = intent.getStringExtra("item");
		Button backBtn = (Button) findViewById(R.id.common_edit_back);
		backBtn.setOnClickListener(this);
		titleTextView = (TextView) findViewById(R.id.common_edit_title);
		titleTextView.setText(title);
		valueEditText = (EditText) findViewById(R.id.common_edit_value);
		itemTextView = (TextView) findViewById(R.id.common_edit_item);
		itemTextView.setText(item);
		saveButton = (Button) findViewById(R.id.common_edit_save);
		saveButton.setOnClickListener(this);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.common_edit, menu);
		return true;
	}

	@Override
	public void onClick(View v) {
		int id = v.getId();
		if(id==R.id.common_edit_save){
			saveOperation();
			finish();
		}else if (id == R.id.common_edit_back) {
			finish();
		}	
		
	}
	
	private void saveOperation(){
		if(title.equals("添加模板")){
			Intent intent = new Intent();  
	        intent.setAction(Constants.ADD_TEMPLATE_INTENT_REFRESH_TEMPLATE_LIST);  
	        intent.putExtra("value",valueEditText.getText().toString().trim() );
	        sendBroadcast(intent); 
		}
	}
}
